﻿using System.Threading;

namespace DetectSys
{
    using System;
    using System.IO;

    public sealed class C
    {
        public const string Platform = "CLIENT";

        public static void Debug(string msg)
        {
            LogtoText("debug", "CLIENT", msg);
        }



        private static object lockobj = new object();
        public static void LogtoText(string model, string method, string content)
        {
            string str = AppDomain.CurrentDomain.BaseDirectory;
            string path = Path.Combine(str, DateTime.Now.ToString("yyyyMMdd") + ".log");
            if (!Directory.Exists(str))
            {
                Directory.CreateDirectory(str);
            }

            if (Monitor.TryEnter(lockobj, 500))
            {
                try
                {
                    using (var stream = File.Open(path, FileMode.Append, FileAccess.Write))
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            string str3 = string.Format("{0}\t{1}\t{2}\t{3}",
                                new object[] {DateTime.Now.ToString("HH:mm:ss"), model, method, content});
                            writer.WriteLine(str3);
                            writer.Close();
                            writer.Dispose();
                            stream.Close();
                            stream.Dispose();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
                finally
                {
                    Monitor.Exit(lockobj);
                }
            }
            
               
        }
    }
}

